package com.haofengsoft.platform.companent.imageview.imageindicator.network;

import java.util.List;

import android.content.Context;
import android.graphics.Bitmap;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;

import com.haofengsoft.platform.companent.imageview.imageindicator.ImageIndicatorView;
import com.haofengsoft.scce.R;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;


/**
 * Network ImageIndicatorView, by urls
 *
 * @author steven-pan
 */
public class NetworkImageIndicatorView extends ImageIndicatorView {

    public NetworkImageIndicatorView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public NetworkImageIndicatorView(Context context) {
        super(context);
    }

    /**
     * 设置显示图片URL列表
     *
     * @param urlList URL列表
     */
    public void setupLayoutByImageUrl(final List<String> urlList) {
        if (urlList == null)
            throw new NullPointerException();

        final int len = urlList.size();
        if (len > 0) {
            for (int index = 0; index < len; index++) {
                DisplayImageOptions options = new DisplayImageOptions.Builder()
                        .showImageOnLoading(R.drawable.loading)
                        .showImageForEmptyUri(R.drawable.loading)
                        .showImageOnFail(R.drawable.loading)
                        .cacheInMemory(true)
                        .imageScaleType(ImageScaleType.EXACTLY_STRETCHED)
                        .considerExifParams(true)
                        .bitmapConfig(Bitmap.Config.RGB_565)
                        .build();
                final ImageView pageItem = new ImageView(getContext());
                LayoutParams params = new LayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
                pageItem.setLayoutParams(params);
                pageItem.setAdjustViewBounds(true);
                ImageLoader.getInstance().displayImage(urlList.get(index), pageItem, options);
                addViewItem(pageItem);
            }
        }
    }


}
